import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class MyThreadPool {

  public  MyThreadPool(int n){
      for (int i = 0; i < n; i++) {
          Thread thread=new Thread(()->{
              while(true) {
                  try {
                      Runnable runnable = blockingDeque.take();
                      runnable.run();
                  } catch (InterruptedException e) {
                      throw new RuntimeException(e);
                  }
              }
          });
          thread.start();
      }
  }

  public BlockingDeque<Runnable> blockingDeque=new LinkedBlockingDeque<>();

  public void submit(Runnable runnable){
      try {
          blockingDeque.put(runnable);
      } catch (InterruptedException e) {
          throw new RuntimeException(e);
      }
  }

    public static void main(String[] args) {
        MyThreadPool myThreadPool=new MyThreadPool(10);
        for (int i = 0; i < 10000; i++) {
            int n=i;
            myThreadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello"+n);
                }
            });
        }
    }
}
